home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / sea of chaos / sea_install.msi / _15C39AAA7726369D39812BD40F01CF6A / _978F66AFB50E4F9AB88D854036321491 < prev    next >
Text File  |  2005-01-30  |  2KB  |  77 lines

  1. //extrudes object away from a light, fading out far edge
  2. //Luke Lenhart
  3. //(C)2004-2005 Digipen Institute of Technology
  4.  
  5. //world,view,projection transforms
  6. float4x4 matWorld, matViewProj;
  7.  
  8. //light position (in world space)
  9. float4 lightPos;
  10.  
  11. //current swipe in position on x axis
  12. float xSwipePos;
  13.  
  14. //shader input
  15. struct VS_INPUT
  16. {
  17.     float4 Pos : POSITION;
  18.     float4 Normal : NORMAL;
  19.     float2 Tex0 : TEXCOORD0;
  20. };
  21.  
  22. //shader output
  23. struct VS_OUTPUT
  24. {
  25.     float4 Pos : POSITION;
  26.     float2 Tex0 : TEXCOORD0;
  27.     float4 Color : COLOR;
  28.     float4 Pos2 : TEXCOORD1;
  29. };
  30.  
  31. //shader code
  32. VS_OUTPUT VShader(VS_INPUT In)
  33. {
  34.     VS_OUTPUT Out;
  35.     
  36.     //copy out source position
  37.     Out.Pos2=In.Pos;
  38.     
  39.     //move us to world space
  40.     float4 pos=mul(matWorld,In.Pos);
  41.     float4 norm=mul(matWorld,In.Normal.xyz);
  42.     
  43.     //calc extrude dist based on x swipe position
  44.     float posMod=saturate((xSwipePos-In.Pos.x));
  45.     posMod=sin(posMod*3.1415926535);
  46.     posMod=pow(posMod,0.33f);
  47.     float extrude_dist=2.05f*posMod;
  48.     
  49.     //calc direction from light to vert
  50.     float3 rayDir=normalize(pos.xyz-lightPos.xyz);
  51.         
  52.     //stuff on the back side should be extruded
  53.     float sideCheck=dot(norm,rayDir);
  54.     if (In.Pos.y>0) //extruded
  55.     {        
  56.         //push vert in direction of ray
  57.         pos.xyz+=rayDir*extrude_dist;
  58.         Out.Tex0.y=0.99f;
  59.     }
  60.     else //fixed
  61.     {
  62.         Out.Tex0.y=0.01f;
  63.     }
  64.  
  65.     //alpha based on extrusion amount    
  66.     Out.Color=float4(1,1,1,posMod-0.1f);
  67.     
  68.     //calc transformed position
  69.     Out.Pos=mul(matViewProj,pos);
  70.     
  71.     //calc tex coord
  72.     Out.Tex0.x=In.Pos.x+In.Pos.z;
  73.  
  74.     //spit out the results
  75.     return Out;
  76. }
  77.